package org.example.pattern.strategy;

import java.util.concurrent.TimeUnit;

public class StrategyB implements Strategy {

    private TObj tObj;
    private String name;

    public StrategyB() {

    }

    public StrategyB(String name, TObj tObj) {
        this.name = name;
        this.tObj = tObj;
    }

    @Override
    public Result<String> validate() {
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (tObj.getNum() == 0) {
            return Result.result(200, this.getName() + " success");
        }
        return Result.result(-10, this.getName() +" error");
    }

    @Override
    public String getName() {
        return this.name;
    }
}
